//
//  BoHuiAlertView.m
//  FactorySale
//
//  Created by 李 on 2020/4/1.
//  Copyright © 2020 主事丫环. All rights reserved.
//

#import "BoHuiAlertView.h"

@implementation BoHuiAlertView

-(instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        
        [self configViewsWithFrame:frame];
    }
    
    return self;
    
}
-(void)configViewsWithFrame:(CGRect)frame
{
    self.frame = frame;
    
    UIView *backView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, KWIDTH, KHEIGHT)];
    backView.backgroundColor = [UIColor colorWithHexString:@"#000000"];
    backView.alpha = 0.5;
    [self addSubview:backView];
    UITapGestureRecognizer * tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(hideBackView)];
    [backView addGestureRecognizer:tap];
    
    UIView *whiteView = [[UIView alloc]initWithFrame:CGRectMake(38, 240, KWIDTH-38-38, 184)];
    whiteView.backgroundColor = [UIColor whiteColor];
    whiteView.layer.cornerRadius = 4;
    [self addSubview:whiteView];
    
    UILabel *titleLab = [[UILabel alloc] init];
    titleLab.text = @"驳回原因";
    titleLab.font =  KFontPingFangSCBold(17);
    titleLab.textAlignment = NSTextAlignmentCenter;
    titleLab.textColor = [UIColor colorWithHexString:@"#333333"];
    titleLab.numberOfLines = 0;
    [whiteView addSubview:titleLab];
    [titleLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(whiteView.mas_left).mas_offset(12);
        make.top.equalTo(whiteView.mas_top).mas_offset(16);
        make.width.mas_greaterThanOrEqualTo(100);
        make.height.mas_equalTo(17);
    }];
    
    self.reasonTextView = [[IQTextView alloc]init];
    self.reasonTextView.placeholder = @"请输入驳回原因";
    self.reasonTextView.font = KFontPingFangSCRegular(12);
    self.reasonTextView.textColor = K333333;
    self.reasonTextView.delegate = self;
    //self.reasonTextView.text =@"";
    self.reasonTextView.backgroundColor =[UIColor colorWithHexString:@"#E5E5E5"];
    [whiteView addSubview:self.reasonTextView];
    [self.reasonTextView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(whiteView.mas_left).mas_offset(20);
        make.top.equalTo(whiteView.mas_top).mas_offset(52);
        make.width.mas_equalTo(KWIDTH-38-38-40);
        make.height.mas_equalTo(80);
        
    }];
    
    
    
    UIButton *sureBtn = [UIButton  buttonWithType:(UIButtonTypeCustom)];
    [sureBtn setTitle:@"确定" forState:(UIControlStateNormal)];
    [sureBtn setTitleColor:[UIColor colorWithHexString:@"#1CAA89"] forState:(UIControlStateNormal)];
    sureBtn.titleLabel.font = KFontPingFangSCBold(15);
    [sureBtn addTarget:self action:@selector(sureBtnAction:) forControlEvents:(UIControlEventTouchUpInside)];
    [whiteView addSubview:sureBtn];
    
    [sureBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(whiteView.mas_left).mas_offset((KWIDTH-38-38-50)/2);
        make.top.equalTo(whiteView.mas_top).mas_offset(153);
        make.width.mas_equalTo(50);
        make.height.mas_equalTo(20);
    }];
    
}
-(void)sureBtnAction:(UIButton *)btn
{
    if (self.sureBtnHandle) {
        self.sureBtnHandle();
    }
}
- (void)textViewDidChange:(UITextView *)textView
{
    if (self.reasonTextViewHandle) {
        self.reasonTextViewHandle(textView.text);
    }
}
- (void)textViewDidEndEditing:(UITextView *)textView{
    
    if (self.reasonTextViewHandle) {
        self.reasonTextViewHandle(textView.text);
    }
    
}
-(void)hideBackView
{
    [self removeFromSuperview];
}

@end
